home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cfengine-1.5.3 / src / patches.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-06  |  6.0 KB  |  321 lines

  1. /* cfengine for GNU
  2.  
  3.         Copyright (C) 1995
  4.         Free Software Foundation, Inc.
  5.  
  6.    This file is part of GNU cfengine - written and maintained 
  7.    by Mark Burgess, Dept of Computing and Engineering, Oslo College,
  8.    Dept. of Theoretical physics, University of Oslo
  9.  
  10.    This program is free software; you can redistribute it and/or modify it
  11.    under the terms of the GNU General Public License as published by the
  12.    Free Software Foundation; either version 2, or (at your option) any
  13.    later version.
  14.  
  15.    This program is distributed in the hope that it will be useful,
  16.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.    GNU General Public License for more details.
  19.  
  20.   You should have received a copy of the GNU General Public License
  21.   along with this program; if not, write to the Free Software
  22.   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
  23.  
  24. */
  25.  
  26.  
  27. /*********************************************************/
  28. /* patches.c                                             */
  29. /*                                                       */
  30. /* Contains any fixes which need to be made because of   */
  31. /* lack of OS support on a given platform                */
  32. /* These are conditionally compiled, pending extensions  */
  33. /* or developments in the OS concerned.                  */
  34. /*********************************************************/
  35.  
  36.  
  37. #include "cf.defs.h"
  38. #include "cf.extern.h"
  39.  
  40. #ifndef HAVE_GETNETGRENT
  41.  
  42. #ifndef const
  43. # define const
  44. #endif
  45.  
  46. /*********************************************************/
  47.  
  48. setnetgrent()
  49.  
  50. {
  51. }
  52.  
  53. /**********************************************************/
  54.  
  55. getnetgrent(a,b,c)
  56.  
  57. char *a, *b, *c;
  58.  
  59. {
  60. *a=NULL;
  61. *b=NULL;
  62. *c=NULL;
  63. return 0;
  64. }
  65.  
  66. /***********************************************************/
  67.  
  68. endnetgrent()
  69.  
  70. {
  71. }
  72.  
  73. #endif
  74.  
  75. #ifndef HAVE_UNAME
  76.  
  77. #ifndef const
  78. # define const
  79. #endif
  80.  
  81. /***********************************************************/
  82. /* UNAME is missing on some weird OSes                     */
  83. /***********************************************************/
  84.  
  85. uname (sys)
  86.  
  87. struct utsname *sys;
  88.  
  89. { char buffer[bufsize], *sp;
  90.  
  91. if (gethostname(buffer,bufsize) == -1)
  92.    {
  93.    perror("gethostname");
  94.    exit(1);
  95.    }
  96.  
  97. strcpy(sys->nodename,buffer);
  98.  
  99. if (strcmp(buffer,AUTOCONF_HOSTNAME) != 0)
  100.    {
  101.    Verbose("This binary was complied on a different host (%s).\n",AUTOCONF_HOSTNAME);
  102.    Verbose("This host does not have uname, so I can't tell if it is the exact same OS\n");
  103.    }
  104.  
  105. strcpy(sys->sysname,AUTOCONF_SYSNAME);
  106. strcpy(sys->release,"cfengine-had-to-guess");
  107. strcpy(sys->machine,"missing-uname(2)");
  108. strcpy(sys->version,"unknown");
  109.  
  110.  
  111.   /* Extract a version number if possible */
  112.  
  113. for (sp = sys->sysname; *sp != '\0'; sp++)
  114.    {
  115.    if (isdigit(*sp))
  116.       {
  117.       strcpy(sys->release,sp);
  118.       strcpy(sys->version,sp);
  119.       *sp = '\0';
  120.       break;
  121.       }
  122.    }
  123.  
  124. return (0);
  125. }
  126.  
  127. #endif
  128.  
  129. /***********************************************************/
  130. /* strstr() missing on old BSD systems                     */
  131. /***********************************************************/
  132.  
  133. #ifndef HAVE_STRSTR
  134.  
  135.  
  136. #ifndef const
  137. # define const
  138. #endif
  139.  
  140. char *strstr(s1,s2)
  141.  
  142. char *s1, *s2;
  143.  
  144. { char *sp;
  145.  
  146. for (sp = s1; *sp != '\0'; sp++)
  147.    {
  148.    if (*sp != *s2)
  149.       {
  150.       continue;
  151.       }
  152.  
  153.    if (strncmp(sp,s2,strlen(s2))== 0)
  154.       {
  155.       return sp;
  156.       }
  157.    }
  158.  
  159. return NULL;
  160. }
  161.  
  162. #endif
  163.  
  164. /***********************************************************/
  165. /* strdup() missing on old BSD systems                     */
  166. /***********************************************************/
  167.  
  168. #ifndef HAVE_STRDUP
  169.  
  170. char *strdup(str)
  171.  
  172. char *str;
  173.  
  174. { char *sp;
  175.  
  176. if (str == NULL)
  177.    {
  178.    return NULL;
  179.    }
  180.  
  181. if ((sp = malloc(strlen(str)+1)) == NULL)
  182.    {
  183.    perror("malloc");
  184.    return NULL;
  185.    }
  186.  
  187. strcpy(sp,str);
  188. return sp; 
  189. }
  190.  
  191. #endif
  192.  
  193.  
  194.  
  195. /***********************************************************/
  196. /* strrchr() missing on old BSD systems                     */
  197. /***********************************************************/
  198.  
  199. #ifndef HAVE_STRRCHR
  200.  
  201. char *strrchr(str,ch)
  202.  
  203. char *str;
  204. char ch;
  205.  
  206. { char *sp;
  207.  
  208. if (str == NULL)
  209.    {
  210.    return NULL;
  211.    }
  212.  
  213. if (strlen(str) == 0)
  214.    {
  215.    return NULL;
  216.    }
  217.  
  218. for (sp = str+strlen(str)-1; sp > str; sp--)
  219.    {
  220.    if (*sp == ch)
  221.       {
  222.       return *sp;
  223.       }
  224.    }
  225.  
  226. return NULL; 
  227. }
  228.  
  229. #endif
  230.  
  231.  
  232. /***********************************************************/
  233. /* strerror() missing on systems                           */
  234. /***********************************************************/
  235.  
  236. #ifndef HAVE_STRERROR
  237.  
  238. char *strerror(err)
  239.  
  240. int err;
  241.  
  242. { static char buffer[20];
  243.  
  244. sprintf(buffer,"Error number %d\n",err);
  245. return buffer; 
  246. }
  247.  
  248. #endif
  249.  
  250. /***********************************************************/
  251. /* putenv() missing on old BSD systems                     */
  252. /***********************************************************/
  253.  
  254. #ifndef HAVE_PUTENV
  255.  
  256.  
  257. #ifndef const
  258. # define const
  259. #endif
  260.  
  261. putenv (s)
  262.  
  263. char *s;
  264.  
  265. {
  266. Verbose("(This system does not have putenv: cannot update CFALLCLASSES\n");
  267. }
  268.  
  269.  
  270. #endif
  271.  
  272.  
  273. /***********************************************************/
  274. /* seteuid/gid() missing on some on posix systems          */
  275. /***********************************************************/
  276.  
  277. #ifndef HAVE_SETEUID
  278.  
  279.  
  280. #ifndef const
  281. # define const
  282. #endif
  283.  
  284. seteuid (uid)
  285.  
  286. uid_t uid;
  287.  
  288. {
  289. #ifdef HAVE_SETREUID
  290. return setreuid(-1,uid);
  291. #else
  292. Verbose("(This system does not have setreuid (patches.c)\n");
  293. return -1; 
  294. #endif 
  295. }
  296.  
  297. #endif
  298.  
  299. /***********************************************************/
  300.  
  301. #ifndef HAVE_SETEGID
  302.  
  303. #ifndef const
  304. # define const
  305. #endif
  306.  
  307. setegid (gid)
  308.  
  309. gid_t gid;
  310.  
  311. {
  312. #ifdef HAVE_SETREGID
  313. return setregid(-1,gid);
  314. #else
  315. Verbose("(This system does not have setregid (patches.c)\n");
  316. return -1; 
  317. #endif 
  318. }
  319.  
  320. #endif
  321.